<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title>Prex Build Guide</title>
  <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
  <meta name="keywords" content="Prex, embedded, real-time, operating system, RTOS, open source, free">
  <meta name="author" content="Kohsuke Ohtani">
  <link rel="stylesheet" type="text/css" href="../default.css" media="screen">
  <link rel="stylesheet" type="text/css" href="../print.css" media="print">
</head>
<body>
<div id="top">
</div>
<div id="middle">

<table id="content" cellpadding="0" cellspacing="0">
  <tbody>

    <tr>
      <td id="header" colspan="2" valign="top">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td id="logo">
            <a href="http://prex.sourceforge.net/">
            <img alt="Prex logo" src="../img/logo.gif" border="0"
            style="width: 250px; height: 54px;"></a>
          </td>
          <td id="brief" align="right" valign="bottom">
            An Open Source, Royalty-free,<br>
	    Real-time Operating System
          </td>
        </tr>
        </table>
      </td>
    </tr>

    <tr>
      <td id="directory" style="vertical-align: top;">
      <a href="http://prex.sourceforge.net/">Prex Home</a> >
      <a href="index.html">Document Index</a> >
      Prex Build Guide
    </tr>
    <tr><td class="pad" colspan="2" style="vertical-align: top;"></td></tr>

    <tr>
      <td id="doc" style="vertical-align: top;">
      <h1>Prex Build Guide</h1>

<i>Version 1.5.1, 2008/10/10</i><br>


<h3>Table of Contents</h3>
<ul>
  <li><a href="#get">Getting Source</a></li>
  <li><a href="#compile">Compiling Prex</a></li>
  <li><a href="#cygwin">Compiling on Windows</a></li>
  <li><a href="#install">Installing OS Image</a></li>
  <li><a href="#platform">Supported Targets</a></li>
  <li><a href="#custom">Customizing OS Image</a></li>
</ul>
<br>


<h2 id="get">Getting Source</h2>
<p>
You can download the source files at the
<a href="http://prex.sourceforge.net/downloads.html">download page</a>.<br>
Some binary files may be available there.
</p>


<h2 id="compile">Compiling Prex</h2>

<h4>Step 1. Prepare Toolchain</h4>
The following packages are required to compile Prex.
<ul>
  <li>GCC 2.95 or later (~4.2)</li>
  <li>GNU Binutils</li>
  <li>GNU Make</li>
</ul>
GCC and Binutils should be built appropriately for your target
architecture if you cross-compile Prex.

<h4>Step 2. Unpack Sources</h4>
Unpack the sources and move to top level directory of the source tree.
<pre class="terminal">$ cd /usr/src
$ tar zxvf prex-X.X.X.tar.gz
$ cd prex-X.X.X
</pre>

<h4>Step 3. Configure</h4>
Setup target architecture and platform.
The following sample shows the setting for i386-pc target.
<pre class="terminal">$ ./configure --target=i386-pc
</pre>

<h4>Step 4. Make</h4>
Run make.<br>
<pre class="terminal">
$ make
</pre>

<h4>(Tips)</h4>
If you want to run 'make' in the subdirectory, you have to set the
SRCDIR as follows:<br>
<pre class="terminal">
$ export SRCDIR=/usr/src/prex-X.X.X
</pre>


<h2 id="cygwin">Compiling on Windows</h2>
<p>
Cygwin is required to build Prex on Windows environment.
</p>
<p>
Please note that we can not use the default gcc version included in Cygwin.
This is because the pre-compiled gcc in Cygwin is built to generate a native Windows binary (PE format).
Since Prex supports only ELF file format, you have to prepare the toolchain
for i386-elf with the following steps.
(Target Platform is i386-pc here.)
</p>

<h4>Step 1. Install Cygwin</h4>

You can find the latest Cygwin setup program at
<a href="http:/www.cygwin.com">this site</a>.

Download setup.exe and run it. During Cygwin installation, you have to select
at least the following packages in addition to the default selection.<br>
<ul>
  <li>make</li>
  <li>binutils</li>
  <li>gcc-core</li>
  <li>flex</li>
  <li>perl</li>
</ul>
Note: These tools are not required to build Prex itself.
They are required to build "binutils and gcc".

<h4>Step 2. Unpack Archives</h4>
You have to download and unpack the following files.

<pre class="terminal">$ cd /usr/src
$ tar zxvf binitils-2.15.tar.gz
$ tar zxvf gcc-core-3.4.3.tar.gz
<!-- Temporary removed
$ tar zxvf newlib-1.13.0.tar.gz--></pre>

<h4>Step 3. Build Binutils</h4>

<p>
Configure and build binutils.
</p>
<pre class="terminal">$ mkdir binutils-2.15-i386-elf
$ cd binutils-2.15-i386-elf
$ ../binutils-2.15/configure --prefix=/usr/local/i386 --target=i386-elf --disable-nls
$ make
$ make install</pre>
<p>
You must set the path to this binutils before compiling gcc.
</p>
<pre class="terminal">$ export PATH=/usr/local/i386/bin:$PATH
$ cd /usr/src</pre>


<h4>Step 4. Build gcc</h4>

<pre class="terminal">$ mkdir gcc-3.4.3-i386-elf
$ cd gcc-3.4.3-i386-elf
$ ../gcc-3.4.3/configure --prefix=/usr/local/i386 --target=i386-elf \
 --with-gnu-as --with-gnu-ld --disable-nls --enable-languages=c --without-headers \
 --without-libs --disable-libssp
$ make LANGUAGES="c"
$ make LANGUAGES="c" install
$ cd /usr/src</pre>



<h4>Step 5. Configure Prex and make</h4>
<pre class="terminal">$ cd prex-X.X.X
$ ./configure --target=i386-pc
$ make
</pre>


<h2 id="install">Installing OS Image</h2>

The method to install an OS image depends on the target platform.
It may be described in the target specific document listed
in the <a href="index.html">Prex document</a>.


<h2 id="platform">Supported Targets</h2>

To know the supported targets, you can use help option for the configure script.

<pre class="terminal">
$ sh configure --help

Usage: configure [options]

 General options:
    --target=TARGET         target system
    --cross-compile=PREFIX  prefix for cros-compile tools
    --no-debug              disable all debug code

 Supported targets:
    i386-pc i386-nommu arm-gba

$ _
</pre>



<h2 id="custom">Customizing OS Image</h2>

<h3>OS Image</h3>
<p>
If you compile the Prex source with "make" command, the OS boot image is created
as "prexos" in the root directory. The file "prexos" must exist in root directory
of the Prex disk/ROM. You can test your own Prex image by replacing the "prexos" in
the OS boot image.
The file "prexos" includes the following files.
</p>
<ul>
  <li>Boot loader</li>
  <li>Kernel module</li>
  <li>Driver module</li>
  <li>Boot task(s)</li>
</ul>

<h3>Directory Organization</h3>
<p>
The structure of the Prex source directory is as follows:
</p>
<pre>
 boot/ ....... Boot loader
 dev/ ........ Device driver module
 sys/ ........ Prex microkernel
 usr/ ........ User mode programs
 include/ .... Common header files
 conf/ ....... Configuration files
 mk/ ......... Common makefiles
 configure ... Configuration script
 Makefile .... Top level makefile
</pre>


<h3>Configuring Build Options</h3>
<p>
You can change the various options to adjust the image for
your target requirement.
The configuration file is prepared for the each target platform.
You can modify the options described in the following file.
</p>
<ul>
  <li>/conf/XXX/config.XXX</li>
</ul>

<pre>
#
# Prex system configuration file
#

#
# Memory address
#
memory		LOADER_BASE	0x00004000
memory		KERNEL_BASE	0x80010000
memory		DRIVER_BASE	AUTODETECT
memory		SYSPAGE_BASE	0x80000000
memory		BOOTIMG_BASE	0x80100000

#
# Make options
#
makeoptions	CFLAGS+= -march=i486 -mtune=pentiumpro
makeoptions	CFLAGS+= -mpreferred-stack-boundary=2

#
# Tunable paramters
#
options 	HZ=1000		# Ticks/second of the clock
options 	TIME_SLICE=50	# Context switch ratio (msec)
options 	OPEN_MAX=16	# Max open files per process
options 	BUF_CACHE=32	# Blocks for buffer cache
options 	FS_THREADS=4	# Number of file system threads
...
</pre>

<h3>Changing Boot Tasks</h3>
<p>
The boot task is a special task which is loaded by kernel directly at boot
time. You can specify your own boot task(s) in "boottasks" option in
the following file.
</p>
<ul>
  <li>/conf/etc/config.files</li>
</ul>

<pre>
#
# Driver modules
#
drivers		$(SRCDIR)/dev/dev.ko

#
# Boot tasks
#
boottasks	$(SRCDIR)/usr/server/boot/boot
boottasks	$(SRCDIR)/usr/server/proc/proc
boottasks	$(SRCDIR)/usr/server/fs/fs
boottasks	$(SRCDIR)/usr/server/exec/exec
...
</pre>





      </td>
    </tr>
    <tr>
      <td id="footer" colspan="2" style="vertical-align: top;">
        <a href="http://sourceforge.net">
        <img src="http://sourceforge.net/sflogo.php?group_id=132028&amp;type=1"
        alt="SourceForge.net Logo" border="0" height="31" width="88"></a><br>
        Copyright&copy; 2005-2008 Kohsuke Ohtani
      </td>
    </tr>

  </tbody>
</table>

</div>
<div id="bottom"></div>

</body>
</html>
